package com.payment.ktb.Fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.payment.ktb.Interface.HttpCallbackListener;
import com.payment.ktb.R;
import com.payment.ktb.constants.HttpActions;
import com.payment.ktb.constants.HttpUrls;
import com.payment.ktb.utils.AlertDialogUtils;
import com.payment.ktb.utils.HttpUtils;
import com.payment.ktb.utils.StringUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/12/4.
 */

public class FragmentAgentManageMyInfo extends BaseFragment {


    private View view;
    TextView tv_fragmentagentmanagemyinfo_orgType;
    TextView tv_fragmentagentmanagemyinfo_orgName;
    TextView tv_fragmentagentmanagemyinfo_openTime;
    TextView tv_fragmentagentmanagemyinfo_orgPhone;
    TextView tv_fragmentagentmanagemyinfo_orgCert;
    TextView tv_fragmentagentmanagemyinfo_orgProfitBank;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragmentagentmanagemyinfo,null);
        tv_fragmentagentmanagemyinfo_orgType = (TextView) view.findViewById(R.id.tv_fragmentagentmanagemyinfo_orgType);
        tv_fragmentagentmanagemyinfo_orgName = (TextView) view.findViewById(R.id.tv_fragmentagentmanagemyinfo_orgName);
        tv_fragmentagentmanagemyinfo_openTime = (TextView) view.findViewById(R.id.tv_fragmentagentmanagemyinfo_openTime);
        tv_fragmentagentmanagemyinfo_orgPhone = (TextView) view.findViewById(R.id.tv_fragmentagentmanagemyinfo_orgPhone);
        tv_fragmentagentmanagemyinfo_orgCert = (TextView) view.findViewById(R.id.tv_fragmentagentmanagemyinfo_orgCert);
        tv_fragmentagentmanagemyinfo_orgProfitBank = (TextView) view.findViewById(R.id.tv_fragmentagentmanagemyinfo_orgProfitBank);

        getOrgSelfInfo();

        return view;


    }



    public void getOrgSelfInfo() {

        progressDialogUtils.showProgress();

        //构造传输参数
        Map<String, String> map = new HashMap<String,String>();
        map.put("timestamp",String.valueOf(new Date().getTime()));

        //向服务器发送请求
        HttpUtils.HttpRequestByVollery(HttpUrls.URL, HttpActions.OrgSelfInfo, map, mQueue, new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                progressDialogUtils.dismissProgress();
                try {
                    JSONObject jsonObject = new JSONObject(response);

                    //L10("L10", "公司账户", 30000),
                    //L20("L20", "公司业务员", 30000)
                    // L30("L30", "办事处", 30000)
                    //L31("L31", "一级代理", 299)
                    //L32("L32", "特约代理", 99)
                    //L33("L33", "经销商", 99)
                    //L40("L40", "通道外放", 99)
                    //L90("L90", "基础签约商户", 3000)
                    String orgTypeName = "未知";
                    switch (jsonObject.optString("orgType")) {

                        case "L10":
                            orgTypeName = "公司账户";
                            break;
                        case "L20":
                            orgTypeName = "公司业务员";
                            break;
                        case "L30":
                            orgTypeName = "办事处";
                            break;
                        case "L31":
                            orgTypeName = "一级代理";
                            break;
                        case "L32":
                            orgTypeName = "特约代理";
                            break;
                        case "L33":
                            orgTypeName = "经销商";
                            break;
                        case "L40":
                            orgTypeName = "通道外放";
                            break;
                        case "L90":
                            orgTypeName = "基础签约商户";
                            break;
                        default:
                            orgTypeName = "未知";
                            break;

                    }

                    tv_fragmentagentmanagemyinfo_orgType.setText(orgTypeName);
                    tv_fragmentagentmanagemyinfo_orgName.setText(jsonObject.optString("orgName"));
                    tv_fragmentagentmanagemyinfo_openTime.setText(jsonObject.optString("openTime"));
                    tv_fragmentagentmanagemyinfo_orgPhone.setText(StringUtils.handelPhone(jsonObject.optString("orgPhone")));
                    tv_fragmentagentmanagemyinfo_orgCert.setText(StringUtils.handelIDNO(jsonObject.optString("orgCert")));
                    tv_fragmentagentmanagemyinfo_orgProfitBank.setText(StringUtils.handleCard(jsonObject.optString("orgProfitBank")));

                } catch (JSONException e) {
                    e.printStackTrace();
                    AlertDialogUtils.showAlertDialog(mContext, getResources().getString(R.string.json_parse_error));
                }
            }

            @Override
            public void onError(VolleyError volleyError) {
                progressDialogUtils.dismissProgress();
                AlertDialogUtils.showAlertDialog(mContext, volleyError.getMessage());
            }
        });


    }
}
